# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libksba
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.6.4
pkgrel=1
pkgdesc="A CMS and X.509 access library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
license=('GPL')
url="https://www.gnupg.org/related_software/libksba/"
depends=("${MINGW_PACKAGE_PREFIX}-libgpg-error")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://gnupg.org/ftp/gcrypt/${_realname}/${_realname}-${pkgver}.tar.bz2"{,.sig})
#These might be signed by any of these keys https://gnupg.org/signature_key.html
validpgpkeys=('6DAA6E64A76D2840571B4902528897B826403ADA' # Werner Koch (dist signing 2020)
              'AC8E115BF73E2D8D47FA9908E98E9B2D19C6C8BD' # Niibe Yutaka (GnuPG Release Key)
)
sha256sums=('bbb43f032b9164d86c781ffe42213a83bf4f2fee91455edfa4654521b8b03b6b'
            'SKIP')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}

  # fix dll name
  autoreconf -fiv
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-shared \
    --enable-static

  make
}

check() {
   cd "${srcdir}/build-${MSYSTEM}"
   make check || true
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make -j1 DESTDIR=${pkgdir} install
  find "${pkgdir}${MINGW_PREFIX}" -name '*.def' -o -name '*.exp' | xargs -rtl1 rm
}
